package com.ljj;

import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Date;

public class test {

//
//        public static void main(String[] args) {
//
//
//
//
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String format1 = format.format(date);
//            System.out.println(format1);
//        }


    public static void main(String[] args) {
        double excelTimestamp = 45319.8490625;

        // Excel时间戳到日期的转换，考虑Excel的日期起点（1900年1月1日）
        LocalDate startDate = LocalDate.of(1900, 1, 1);
        long daysSinceEpoch = (long)excelTimestamp - 2; // 减2是因为Excel的日期系统认为1900年是闰年，但实际上不是
        LocalDate datePart = startDate.plusDays(daysSinceEpoch);

        // 处理时间部分
        double fractionalDay = excelTimestamp - Math.floor(excelTimestamp);
        long millisIntoDay = (long)(fractionalDay * 24 * 60 * 60 * 1000);
        LocalTime timePart = LocalTime.ofNanoOfDay(millisIntoDay * 1_000_000);

        LocalDateTime dateTime = LocalDateTime.of(datePart, timePart);


        System.out.println(dateTime);

        ZonedDateTime zonedDateTime = dateTime.atZone(ZoneId.systemDefault());

        // 将ZonedDateTime转换为Date
        Date date = Date.from(zonedDateTime.toInstant());

        System.out.println("Converted Date: " + date);
    }




}


